from django.contrib import admin
from django.contrib.contenttypes.admin import GenericStackedInline
from mptt.admin import MPTTModelAdmin
from .models import Comment, Message, Notification

@admin.register(Comment)
class CommentAdmin(MPTTModelAdmin):
    list_display = ('author', 'article', 'content', 'parent','parent_content', 'is_approved', 'likes_count','created_date')
    list_per_page = 15
    search_fields = ('content', 'user__username')
    raw_id_fields = ('author', 'article')
   #list_display显示的parent字段，显示的是评论的父评论，而不是MPTTModelAdmin的parent字段





@admin.register(Message)
class MessageAdmin(admin.ModelAdmin):
    list_display = ('sender', 'receiver','content','status', 'is_sender_deleted', 'is_receiver_deleted','created_date')
    list_filter = ('status', 'created_date')
    search_fields = ('content', 'sender__username', 'receiver__username')
    raw_id_fields = ('sender', 'receiver')
    readonly_fields = ('created_date',)

@admin.register(Notification)
class NotificationAdmin(admin.ModelAdmin):
    list_display = ('id', 'title','receiver', 'sender', 'verb', 'status',
                    'is_sender_deleted', 'is_receiver_deleted', 'timestamp')
    list_filter = ('verb', 'status', 'is_sender_deleted', 'is_receiver_deleted', 'timestamp')
    search_fields = ('receiver__username', 'sender__username', 'content')
    list_editable = ('status', 'is_sender_deleted', 'is_receiver_deleted')
    raw_id_fields = ('receiver', 'sender')
    date_hierarchy = 'timestamp'
    ordering = ('-timestamp',)
    readonly_fields = ('timestamp',)
    fieldsets = (
        ('基础信息', {
            'fields': ('receiver', 'sender', 'verb', 'title','content')
        }),
        ('状态管理', {
            'fields': ('status', 'is_sender_deleted', 'is_receiver_deleted','system_level')
        }),
        ('时间戳', {
            'fields': ('timestamp',),
            'classes': ('collapse',)
        })
    )


